#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#


class Mymeta(type):
    def __init__(self, cls_name, cls_obj, cls_dic):
        super(Mymeta, self).__init__(cls_name, cls_obj, cls_dic)
        obj = self.__new__(self)  # 创建一个空对象
        self.__init__(obj, "1.1.1.1", 9999)  # 为类赋予其独有属性
        self._instance = obj  # 添加一个_instance属性

    def __call__(self, *args, **kwargs):
        # print("_instance--> ", self._instance.__dict__)
        if len(args) == 0 and len(kwargs) == 0:
            return self._instance
        obj = self.__new__(self)
        self.__init__(obj, *args, **kwargs)
        return obj


class Mysql(object, metaclass=Mymeta):
    def __init__(self, host, port):
        self.host = host
        self.port = port


m1 = Mysql()
m2 = Mysql()
print(m1)
print(m2)

x = Mysql("1.1.1.1", 3333)
print(x)
